www.gusucode.com > VC++ ICPQ聊天室源程序-源码程序 > VC++ ICPQ聊天室源程序-源码程序/code/ChartRoomClient/ChartRoomDlg.cpp
// ChartRoomDlg.cpp : implementation file // Download by http://www.NewXing.com #include "stdafx.h" #include "ChartRoomClient.h" #include "ChartRoomDlg.h" extern SOCKET g_socket; extern CChartRoomClientApp theApp; extern CString g_msg; //extern ULNode* g_userlist; #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CChartRoomDlg dialog CChartRoomDlg::CChartRoomDlg(CWnd* pParent /*=NULL*/) : CDialog(CChartRoomDlg::IDD, pParent) { //{{AFX_DATA_INIT(CChartRoomDlg) m_msg = _T(""); m_inputmsg = _T(""); //}}AFX_DATA_INIT m_hIcon = AfxGetApp()->LoadIcon(IDR_APPICON); } void CChartRoomDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CChartRoomDlg) DDX_Control(pDX, IDC_INPUTMSG, m_inputedit); DDX_Text(pDX, IDC_SHOWMSG, m_msg); DDX_Text(pDX, IDC_INPUTMSG, m_inputmsg); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CChartRoomDlg, CDialog) //{{AFX_MSG_MAP(CChartRoomDlg) ON_MESSAGE(WM_HASMSG,OnHasMsg) ON_WM_QUERYDRAGICON() ON_WM_PAINT() ON_BN_CLICKED(IDC_QUIT, OnQuit) ON_BN_CLICKED(IDC_SEND, OnSend) ON_WM_CLOSE() ON_WM_SHOWWINDOW() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CChartRoomDlg message handlers BOOL CChartRoomDlg::OnInitDialog() { CDialog::OnInitDialog(); SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon theApp.m_hmsgdlg = this->GetSafeHwnd(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } HCURSOR CChartRoomDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CChartRoomDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } // Do not call CDialog::OnPaint() for painting messages } LRESULT CChartRoomDlg::OnHasMsg(WPARAM wParam, LPARAM lParam) { m_msg = g_msg; UpdateData(FALSE); SendDlgItemMessage(IDC_SHOWMSG,WM_VSCROLL,SB_BOTTOM,0); return 0; } void CChartRoomDlg::OnQuit() { shutdown(g_socket, SD_SEND); CDialog::OnCancel(); } void CChartRoomDlg::OnSend() { UpdateData(TRUE); if (m_inputmsg.GetLength() ==0 ) { MessageBox("不能发空信息哟!^_^","提示"); return; } m_inputmsg += "\n\r"; CChartRoomClientApp::SendThreadFunc((LPVOID)((LPCTSTR)m_inputmsg)); m_inputedit.SetFocus(); m_inputmsg = ""; UpdateData(FALSE); } void CChartRoomDlg::OnClose() { shutdown(g_socket, SD_SEND); CDialog::OnClose(); } /*void CChartRoomDlg::ListUser() { LV_ITEM lvitem; ULNode *ptr = g_userlist; int i=0,iPos; while(ptr) { lvitem.mask=LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM; lvitem.iItem=i; lvitem.iSubItem=0; lvitem.pszText=ptr->name; lvitem.lParam=i; iPos=m_ListCtrl.InsertItem(&lvitem);//返回表项插入后的索引号 ptr = ptr->next; i++; } }*/ //before chat-room dialog showing , there is a welcome message void CChartRoomDlg::OnShowWindow(BOOL bShow, UINT nStatus) { CDialog::OnShowWindow(bShow, nStatus); ::SendMessage(theApp.m_hmsgdlg , WM_HASMSG , NULL, NULL); //show reserve message }